package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {
    @Override
    public List<SpecParamDTO> queryParams(Long categoryId, Long groupId, Boolean searching) {
        List<SpecParam>list=query().eq(categoryId != null,"category_id",categoryId)
                .eq(groupId != null, "group_id", groupId)
                .eq(searching != null, "searching", searching)
                .list();
        return SpecParamDTO.convertEntityList(list);
    }

    /**
     * 新增规格组参数
     * @param paramDTO
     */
    @Override
    public void saveParam(SpecParamDTO paramDTO) {
        SpecParam specParam = paramDTO.toEntity(SpecParam.class);
        save(specParam);
    }

    /**
     * 修改规格组参数
     * @param paramDTO
     */
    @Override
    public void updateById(SpecParamDTO paramDTO) {
        updateById(paramDTO.toEntity(SpecParam.class));
    }
}
